﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KryptecizerBase;
using Kryptonalysis.EventArguments;
using Kryptonalysis.Statistics;

namespace Kryptonalysis
{
    /// <summary>
    /// Analyzer for KryptoTexts
    /// </summary>
    public abstract class TextBasedAnalyzer : Analyzer
    {
        #region Member
        protected KryptoText _KryptoText;
        protected AnalysisStatistic stats;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the encrypted krypto text.
        /// </summary>
        /// <value>The encrypted krypto text.</value>
        public KryptoText EncryptedKryptoText
        {
            get { return _KryptoText; }
            set { _KryptoText = value; }
        }
        #endregion

        /// <summary>
        /// Method to detect the password.
        /// Calls the OnAnalysisStartet- and the OnAnalysisEndet-method.
        /// Uses the abstract DetectPassword-method.
        /// </summary>
        /// <returns>the password</returns>
        public override string DetectPassword()
        {
            OnAnalysisStartet();
            string pw = DetectPassword(_KryptoText.Clone());
            OnAnalysisEndet(new AnalysisEndedEventArgs(pw, stats));
            return pw;
        }

        /// <summary>
        /// Abstract method to detect the password.
        /// </summary>
        /// <param name="kryptoText">The krypto text.</param>
        /// <returns>the password</returns>
        protected abstract string DetectPassword(KryptoText kryptoText);
    }
}
